package com.example.project_dish;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import com.example.project_dish.Capital.CapitalActivity;
import com.example.project_dish.Dishes.SelectDishActivity;
import com.example.project_dish.Order.MyOrderActivity;

public class OrderFoodActivity extends AppCompatActivity implements View.OnClickListener{

    private Button select_dish;
    private Button comment;
    private Button my_order;
    private Button end_login;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_order_food);

        // 设置状态栏透明
        method.status_bar(this);
        if(this.getSupportActionBar() != null){
            this.getActionBar().hide();
        }
        //获取四个按钮
        select_dish = findViewById(R.id.select_dish);
        comment = findViewById(R.id.comment);
        my_order = findViewById(R.id.my_order);
        end_login = findViewById(R.id.end_login);

        select_dish.setOnClickListener(this);
        comment.setOnClickListener(this);
        my_order.setOnClickListener(this);
        end_login.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.select_dish:
                Intent intent = new Intent(OrderFoodActivity.this, SelectDishActivity.class);
                startActivity(intent);
                break;
            case R.id.comment:
                Intent intent1 = new Intent(OrderFoodActivity.this, CapitalActivity.class);
                startActivity(intent1);
                break;
            case R.id.my_order:
                Intent intent2 = new Intent(OrderFoodActivity.this, MyOrderActivity.class);
                startActivity(intent2);
                break;
            case R.id.end_login:
                AlertDialog.Builder builder = new AlertDialog.Builder(this);  //创建 一个提示对话框的构造者对象
                builder.setTitle("提示框");//设置弹出对话框的标题
                builder.setIcon(R.drawable.index);//设置弹出对话框的图标
                builder.setMessage("您是否退出登录?");//设置弹出对话框的内容
                builder.setCancelable(true);//能否被取消
                builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    //正面按钮
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        Intent intent3 = new Intent(OrderFoodActivity.this, MainActivity.class);
                        startActivity(intent3);
                    }
                });
                builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    //反面按钮
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        Toast.makeText(OrderFoodActivity.this, "您取消了退出登录！", Toast.LENGTH_SHORT).show();
                        //不执行任何操作
                        dialogInterface.cancel();
                    }
                });
                builder.show();
                break;
        }
    }
}